import React, {createContext, Dispatch, ReactNode, SetStateAction, useContext, useState} from 'react';


interface DndContextValue {
    type: string,
    data: unknown
}

const DnDContext = createContext<[DndContextValue | undefined, Dispatch<SetStateAction<DndContextValue | undefined>>]>([undefined, () => {}]);

interface DnDProviderProp {
    children: ReactNode;
}

export const DnDProvider: React.FC<DnDProviderProp> = ({children}) => {
    const [type, setType] = useState<DndContextValue>();

    return (
        <DnDContext.Provider value={[type, setType]}>
            {children}
        </DnDContext.Provider>
    );
}

export const useDnD = () => {
    return useContext(DnDContext);
}

export default DnDContext;

